package org.daisy.springbootdemo;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping("/r1")
    public String r1(String keyword){
        return "接收参数:"+keyword;
    }
    @RequestMapping("/r2")
    public String r2(String username,String password){
        return "username:"+username+" password:"+password;
    }

    @RequestMapping("/r3")
    public String r3(UserInfo userInfo){
        return userInfo.toString();
    }

    @RequestMapping("/r4")
    public String r4(@RequestParam("p") String password){
        return "password:"+password;
    }

    @RequestMapping("/r5")
    public String r5(String[] arr){
        return "arr:"+ Arrays.toString(arr);
    }

    @RequestMapping("/r6")
    public String r6(@RequestParam ArrayList<Integer> list){
        return "list:"+ list.toString();
    }

    @RequestMapping("/r7")
    public String r7(@RequestBody UserInfo userInfo){
        return  userInfo.toString();
    }

    @RequestMapping("/article/{articleId}/{type}")
    public String r8(@PathVariable Integer articleId,@PathVariable String type){
        return "articleId:"+articleId+" type:"+type;
    }

    @RequestMapping("/r9")
    public String r9(MultipartFile file) throws IOException {
        file.transferTo(new File("D:\\temp\\"+file.getOriginalFilename()));
        return "文件上传成功";
    }
}
